home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / mawk.zip / KW.C < prev    next >
C/C++ Source or Header  |  1991-04-07  |  2KB  |  84 lines

  1.  
  2. /********************************************
  3. kw.c
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the Awk programming language as defined in
  8. Aho, Kernighan and Weinberger, The AWK Programming Language,
  9. Addison-Wesley, 1988.
  10.  
  11. See the accompaning file, LIMITATIONS, for restrictions
  12. regarding modification and redistribution of this
  13. program in source or binary form.
  14. ********************************************/
  15.  
  16.  
  17. /* $Log:    kw.c,v $
  18.  * Revision 2.1  91/04/08  08:23:23  brennan
  19.  * VERSION 0.97
  20.  * 
  21. */
  22.  
  23.  
  24. /* kw.c */
  25.  
  26.  
  27. #include "mawk.h"
  28. #include "symtype.h"
  29. #include "parse.h"
  30. #include "init.h"
  31.  
  32.  
  33. static struct kw {
  34. char *text ;
  35. short kw ;
  36. }  keywords[] = {
  37.  
  38. "print", PRINT,
  39. "printf", PRINTF,
  40. "do" , DO ,
  41. "while" , WHILE ,
  42. "for" , FOR ,
  43. "break" , BREAK ,
  44. "continue" , CONTINUE ,
  45. "if" , IF ,
  46. "else", ELSE ,
  47. "in" , IN ,
  48. "delete", DELETE ,
  49. "split" , SPLIT ,
  50. "match" , MATCH_FUNC ,
  51. "BEGIN" , BEGIN,
  52. "END" ,   END ,
  53. "exit" , EXIT ,
  54. "next" , NEXT ,
  55. "return", RETURN,
  56. "getline", GETLINE,
  57. "sub" , SUB,
  58. "gsub", GSUB,
  59. "function", FUNCTION,
  60. (char *) 0 , 0 } ;
  61.  
  62. /* put keywords in the symbol table */
  63. void kw_init()
  64. { register struct kw *p = keywords ;
  65.   register SYMTAB *q ;
  66.  
  67.   while ( p->text )
  68.   { q = insert( p->text ) ;
  69.     q->type = ST_KEYWORD ;
  70.     q->stval.kw = p++ -> kw ;
  71.   }
  72. }
  73.  
  74. /* find a keyword to emit an error message */
  75. char *find_kw_str( kw_token )
  76.   int kw_token ;
  77. { struct kw *p = keywords ;
  78.  
  79.   for( p = keywords ; p->text ; p++ )
  80.         if ( p->kw == kw_token )  return p->text ;
  81.   /* search failed */
  82.   return (char *) 0 ;
  83. }
  84.